package lec10api2;

import java.util.Arrays;
import java.util.Comparator;

public class Point implements Comparable<Point> {//Context
    int x, y;//field

    public static void main(String[] args) {
        Point[] points = new Point[10];
        for (int i = 0; i < points.length; i++) {
            points[i] = new Point();
            points[i].x = (int) (Math.random() * 100);
            points[i].y = (int) (Math.random() * 100);
        }
        // Arrays.sort(points);
        Arrays.sort(points, new Comparator<Point>() {
            @Override
            public int compare(Point px, Point py) {
                return px.y - py.y;
            }
        });
        for (Point point : points) {
            System.out.println(point.toString());
        }

    }

    @Override
    public String toString() {
        return String.format("(%d,%d)", this.x, y);
    }

    @Override
    public int compareTo(Point that) {
        return this.x - that.x;
    }
}
